<template>
  <el-dialog
      :title="!dataForm.emrYsId ? '新增' : '修改'"
      :close-on-click-modal="false"
      :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()"
             label-width="80px">
<el-form-item label="医生姓名" prop="emrYsName">
  <el-input v-model="dataForm.emrYsName" placeholder="医生姓名"></el-input>

</el-form-item>
<el-form-item label="医生职称" prop="emrYsTitle">
  <el-input v-model="dataForm.emrYsTitle" placeholder="医生职称"></el-input>

</el-form-item>
<el-form-item label="医生性别" prop="emrYsSex">
  <el-select placeholder="医生性别" v-model="dataForm.emrYsSex">
    <el-option label="男" :value="1"></el-option>
    <el-option label="女" :value="0"></el-option>
  </el-select>
</el-form-item>
<el-form-item label="所属科室" prop="emrYsSection">
  <el-input v-model="dataForm.emrYsSection" placeholder="所属科室"></el-input>

</el-form-item>
<el-form-item label="联系电话" prop="emrYsPhone">
  <el-input v-model="dataForm.emrYsPhone" placeholder="联系电话"></el-input>

</el-form-item>
<el-form-item label="登录密码" prop="emrYsPwd">
  <el-input v-model="dataForm.emrYsPwd" placeholder="登录密码"></el-input>

</el-form-item>
<el-form-item label="出生日期" prop="emrYsBirth">
  <el-input v-model="dataForm.emrYsBirth" placeholder="出生日期"></el-input>

</el-form-item>
<el-form-item label="创建日期" prop="emrYsCreate">
  <el-input v-model="dataForm.emrYsCreate" placeholder="创建日期"></el-input>

</el-form-item>
<el-form-item label="医生头像" prop="emrYsImg">
  <el-input v-model="dataForm.emrYsImg" placeholder="医生头像"></el-input>

</el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          emrYsId: 0,
          emrYsName: '',
          emrYsTitle: '',
          emrYsSex: '',
          emrYsSection: '',
          emrYsPhone: '',
          emrYsPwd: '',
          emrYsBirth: '',
          emrYsCreate: '',
          emrYsImg: ''
        },
        dataRule: {
          emrYsName: [
            { required: true, message: '医生姓名不能为空', trigger: 'blur' }
          ],
          emrYsTitle: [
            { required: true, message: '医生职称不能为空', trigger: 'blur' }
          ],
          emrYsSex: [
            { required: true, message: '医生性别不能为空', trigger: 'blur' }
          ],
          emrYsSection: [
            { required: true, message: '所属科室不能为空', trigger: 'blur' }
          ],
          emrYsPhone: [
            { required: true, message: '联系电话不能为空', trigger: 'blur' }
          ],
          emrYsPwd: [
            { required: true, message: '登录密码不能为空', trigger: 'blur' }
          ],
          emrYsBirth: [
            { required: true, message: '出生日期不能为空', trigger: 'blur' }
          ],
          emrYsCreate: [
            { required: true, message: '创建日期不能为空', trigger: 'blur' }
          ],
          emrYsImg: [
            { required: true, message: '医生头像不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.emrYsId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.emrYsId) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrysinfo/info/${this.dataForm.emrYsId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.emrYsName = data.emrYsInfo.emrYsName
                this.dataForm.emrYsTitle = data.emrYsInfo.emrYsTitle
                this.dataForm.emrYsSex = data.emrYsInfo.emrYsSex
                this.dataForm.emrYsSection = data.emrYsInfo.emrYsSection
                this.dataForm.emrYsPhone = data.emrYsInfo.emrYsPhone
                this.dataForm.emrYsPwd = data.emrYsInfo.emrYsPwd
                this.dataForm.emrYsBirth = data.emrYsInfo.emrYsBirth
                this.dataForm.emrYsCreate = data.emrYsInfo.emrYsCreate
                this.dataForm.emrYsImg = data.emrYsInfo.emrYsImg
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/hospital/emrysinfo/${!this.dataForm.emrYsId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'emrYsId': this.dataForm.emrYsId || undefined,
                'emrYsName': this.dataForm.emrYsName,
                'emrYsTitle': this.dataForm.emrYsTitle,
                'emrYsSex': this.dataForm.emrYsSex,
                'emrYsSection': this.dataForm.emrYsSection,
                'emrYsPhone': this.dataForm.emrYsPhone,
                'emrYsPwd': this.dataForm.emrYsPwd,
                'emrYsBirth': this.dataForm.emrYsBirth,
                'emrYsCreate': this.dataForm.emrYsCreate,
                'emrYsImg': this.dataForm.emrYsImg
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
